/*
 * @Author: your name
 * @Date: 2022-03-29 19:48:40
 * @LastEditTime: 2022-03-29 19:48:40
 * @LastEditors: Please set LastEditors
 * @Description: 用于根据不同环境读取相应的配置文件。
 * @FilePath: \blog-api\config\env.ts
 */
import * as fs from 'fs';
import * as path from 'path';
const isProd = process.env.NODE_ENV === 'production';

function parseEnv() {
    const localEnv = path.resolve('.env');
    const prodEnv = path.resolve('.env.prod');

    if (!fs.existsSync(localEnv) && !fs.existsSync(prodEnv)) {
        throw new Error('缺少环境配置文件');
    }

    const filePath = isProd && fs.existsSync(prodEnv) ? prodEnv : localEnv;
    return { path: filePath };
}
export default parseEnv();